home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 5 / BBS in a Box -Volume V (BBS in a Box) (April 1992).iso / Files / Bus / A / 4D BACKUP.cpt / BACKUP & RESTORE.text < prev    next >
Encoding:
Text File  |  1988-02-27  |  8.5 KB  |  176 lines  |  [TEXT/MSWD]

  1. Backup & Restore
  2. Drop-In 4th Dimension Utilities
  3.  
  4. Written By
  5. Kenneth A. Craig
  6. 195 10th St. NW
  7. Atlanta, GA  30318
  8.  
  9. GEnie : K.CRAIG
  10. Compuserve : 76210,16
  11.  
  12. THESE PROCEDURES ARE NOT FREE !!!
  13. YOU ARE REQUIRED TO CONTACT ME IN SOME WAY (SEND ME A POSTCARD, A LETTER, A DISK, A PEN OR PENCIL, LOTS OF MONEY, OR ANYTHING USEFUL TO LET ME KNOW THAT SOMEONE OUT THERE APPRECIATES MY SIMPLE GESTURES TO HELP OTHER PROGRAMMERS.
  14. I AM A POOR, STARVING STUDENT AT GEORGIA TECH (GO JACKETS!!!) AND CAN USE ANY HELPFUL INFORMATION, ADVICE, CARS, ETC. TO GET ME THROUGH THESE LEAN YEARS.
  15. Also, please give me credit for these procedures if you use them commercially (just leave the comments in). 
  16. There is no guarantee of the performance of these procedures, written or implied, and neither I, nor Information Management, Inc., nor anyone associated with us assume any liability for their performance.  The archiving and subsequent restoration of data is a very dangerous procedure which can result in data loss and lost time (everybody knows that), these procedures are intended to ease the burden of writing custom made backup and restore routines for each database created.
  17.  
  18. Enough of the legal mumbo jumbo, what does it really do ?
  19.  
  20. BACKUP and RESTORE are two relatively simple procedures for 4D which can just be dropped into any 4D database (along with a small proc.ext file) to allow you, with no customization necessary, to archive all data for that database into one file and restore it at a later date.  They use three external procedures provided by Acius in their December 1987 developer mailings (now available on BBS's everywhere).  
  21.     DataBaseName - gets the name of the current database
  22.     GetNumFiles - gets the total number of files in the database
  23.     GetFileNames - gets the name of a file from within the database
  24. These are included in the file proc.ext which should be dropped into the database folder before the procedures below are pasted into a 4D global procedures.  You can also move these into the database.res file using 4D External Mover provided with 4th Dimension.
  25. Just paste these procedures into 4D globals and supply menu commands (Backup Database, and Restore Database From Backup) which call the respective procedures.  You should provide password protection for RESTORE to only the highest level user.
  26.  
  27. Possible modifications ...
  28. Removal of the safety feature of saving the number of files in the database.  This would allow you to transfer all data from one database into an updated version in which files have been added or deleted from the structure.
  29. Removal of the database name from the backup.  This, along with the above change, would let you move data from two completely different databases that share some subset of each other's structure (exactly !!!).
  30. More powerful options dealing with deleting or appending to current data, or deleting only duplicates, etc.  I have no need for it so I haven't even attempted it.
  31.  
  32. Once more I beg of you to send me some correspondence, physical or electronic telling me in what kind of database you use these in, how you like it, etc., send me some of your own work, from 4D or other things, send me some compensation or advice or anything useful, (beggars can't be choosers).
  33.  
  34. -------------------------------------------------------------
  35. BACKUP
  36. -------------------------------------------------------------
  37.    `**********************************
  38.    `BACKUP Backs Up All Files In The Database
  39.    `Kenneth A. Craig
  40.    `Information Management Inc.
  41.    `376 Oakdale Rd
  42.    `Atlanta, GA  30307
  43.    `(404) 523-1132
  44.    `CIS 76210,16
  45.    `GEnie K.CRAIG
  46.    `Be sure you have the externals DataBaseName, GetNumFiles, GetFileName
  47.    `   available in either the System Folder or the Application folder as "proc.ext"
  48.    `   or installed into the Database.res file.
  49.    `------------------------------------------------
  50.    `NOTE : DO NOT rename the database or any files, or
  51.    `      change the fields in any of the files or the the
  52.    `      file will not RESTORE properly.
  53.    `      Just don't change the structure at all !!!
  54.    `**********************************
  55. SET CHANNEL(12;"")
  56. If (OK=1)
  57.   OPEN WINDOW(Screen width/2-150;Screen height/2-100;Screen width/2+150;Screen height/2+100)
  58.      `Save the database name as a safety feature so
  59.      `you can't restore the wrong database's data accidentally.
  60.   DataBaseName (xDBase)
  61.   MESSAGE("Backing Up  "+xDBase+"."+Char(13))
  62.   SEND VARIABLE(xDBase)
  63.   MESSAGE("Saving Date As :"+String(Current date)+Char(13))
  64.      `Save date and time of the backup.
  65.   xDate:=Current date
  66.   SEND VARIABLE(xDate)
  67.   MESSAGE("Saving Time As :"+Time string(Current time)+Char(13))
  68.   xTime:=Current time
  69.   SEND VARIABLE(xTime)
  70.      `Save the number of files as another precation.  Two databases
  71.      `can have the same name but probably won't have the same number
  72.      `of files.
  73.   GetNumFiles (xFiles)
  74.   MESSAGE("Saving Number Of Files As :"+String(xFiles)+Char(13))
  75.   SEND VARIABLE(xFiles)
  76.   xCount:=1
  77.   While (xCount<=xFiles)
  78.        `ONE MORE SAFETY FEATURE
  79.        `Save the name of each file before the data
  80.        `This one can be a real pain in the (bleep) if you decide to
  81.        `rename files after a backup (I'm really indecisive about file
  82.        `names and other things and I've caused myself problems here). 
  83.     GetFile (xCount;xName)
  84.     MESSAGE("Backing Up File :"+xName+Char(13))
  85.     SEND VARIABLE(xName)
  86.     EXECUTE("ALL RECORDS(["+xName+"])")
  87.     EXECUTE("xSize:=Records in selection(["+xName+"])")
  88.     SEND VARIABLE(xSize)
  89.     EXECUTE("apply to selection(["+xName+"];send record(["+xName+"]))")
  90.     xCount:=xCount+1
  91.   End while 
  92.   CLOSE WINDOW
  93.   SET CHANNEL(11)
  94. End if 
  95.  
  96. -------------------------------------------------------------
  97. RESTORE
  98. -------------------------------------------------------------
  99.  
  100.    `**********************************
  101.    `RESTORE Restores All Files Backed Up With BACKUP
  102.    `Kenneth A. Craig
  103.    `Information Management Inc.
  104.    `376 Oakdale Rd
  105.    `Atlanta, GA  30307
  106.    `(404) 523-1132
  107.    `CIS 76210,16
  108.    `GEnie K.CRAIG
  109.    `Be sure you have the externals DataBaseName, GetNumFiles, GetFileName
  110.    `   available in either the System Folder or the Application folder as "proc.ext"
  111.    `   or installed into the Database.res file.
  112.    `------------------------------------------------
  113.    `NOTE : DO NOT rename the database or any files, or
  114.    `      change the fields in any of the files or the the
  115.    `      file will not RESTORE properly.
  116.    `      Just don't change the structure at all !!!
  117.    `**********************************
  118. SET CHANNEL(10;"")
  119. If (OK=1)
  120.   OPEN WINDOW(Screen width/2-150;Screen height/2-100;Screen width/2+150;Screen height/2+100)
  121.      `Get the name of the backed up database and compare
  122.      `it to the current name.  If different then quit the backup.
  123.   DataBaseName (xDBase)
  124.   RECEIVE VARIABLE(yDBase)
  125.   If (xDBase=yDBase)
  126.     MESSAGE("Restoring "+xDBase+"."+Char(13))
  127.     RECEIVE VARIABLE(xDate)
  128.     RECEIVE VARIABLE(xTime)
  129.        `Now compare the number of files in the database.  This could be removed
  130.        `if you want to add and delete files, as long as you keep the file names
  131.        `in the backup file and use them in the restore (see below) and don't change
  132.        `the file names.  The order of files doesn't matter in this backup so this would
  133.        `not be too difficult to do.
  134.     GetNumFiles (xFiles)
  135.     RECEIVE VARIABLE(yFiles)
  136.     If (xFiles=yFiles)
  137.       CONFIRM("Backup Date :"+String(xDate)+Char(13)+"Backup Time :"+Time string(xTime)+Char(13)+"Restore Data?")
  138.       If (OK=1)
  139.         xCount:=1
  140.         While (xCount<=xFiles)
  141.              `Get the file name and number of records backed up.          
  142.           RECEIVE VARIABLE(xName)
  143.           RECEIVE VARIABLE(xSize)
  144.           MESSAGE("Restoring File :"+xName+"  -  "+String(xSize)+" Records."+Char(13))
  145.           Flush:=0
  146.           BEEP(5)
  147.           BEEP(5)
  148.              `Lets you delete the current data or just append the back up data.
  149.           CONFIRM("Delete All Records Of "+xName+" Before Restoring?")
  150.           If (OK=1)
  151.             EXECUTE("ALL RECORDS(["+xName+"])")
  152.             EXECUTE("delete selection(["+xName+"])")
  153.           End if 
  154.           xIndex:=1
  155.           While (xIndex<=xSize)
  156.             EXECUTE("create record(["+xName+"])")
  157.             EXECUTE("receive record(["+xName+"])")
  158.             EXECUTE("save record(["+xName+"])")
  159.             xIndex:=xIndex+1
  160.           End while 
  161.           Flush:=1
  162.           xCount:=xCount+1
  163.         End while 
  164.       End if 
  165.     Else 
  166.       ALERT("The file structure has changed and this is no longer valid backup data.")
  167.     End if 
  168.   Else 
  169.     ALERT("This is a backup file for the database "+yDBase+".")
  170.   End if 
  171.   CLOSE WINDOW
  172.   SET CHANNEL(11)
  173. End if 
  174.  
  175.  
  176.